package com.hitangjun.pattern.templatemethod.InterestRate;

public abstract class Account {
	protected String accountNumber;

	/**
	 * default constructor
	 * 
	 */
	public Account() {
		accountNumber = null;
	}

	public Account(String accountNumber) {
		this.accountNumber = accountNumber;
	}

	/**
	 * 模板方法，计算利息数额
	 * @return
	 */
	final public double calculateInterest() {
		double interestRate = doCalculateInterestRate();
		String accountType = doCalculateAccountType();
		double amount = calculateAmount(accountType, accountNumber);
		return amount * interestRate;
	}

	/**
	 * 基本方法，已经实现
	 * @return
	 */
	final public double calculateAmount(String accountType, String accountNumber2) {
		// receive amount from database
		return 7243.00D;
	}

	/**
	 * 基本方法，留给子类实现
	 * @return
	 */
	abstract protected String doCalculateAccountType();

	/**
	 * 基本方法，留给子类实现
	 * @return
	 */
	abstract protected double doCalculateInterestRate();
}
